<template>
  <div class="container">
    <div class="proName">{{name}}</div>
    <div class="proDetail">
      <div class="item" v-for="(item,index) in info" :key="'info'+index">
        <div>{{item.fieldName}}</div>
        <div>{{item.fieldValue}}</div>
      </div>

      <div class="btn">
        <van-button
          type="default"
          color="#DBB47F"
          style="width:100%"
          @click="confirmOrder()"
          v-if="state == 0"
        >确认订单</van-button>

        <van-button type="default" color="#999" style="width:100%" v-if="state == 1">已确认订单</van-button>
      </div>
    </div>
  </div>
</template>
<script>
import Api from "./../api/api";
import { Toast } from "vant";
export default {
  data() {
    return {
      info: [],
      name: "",
      state: ""
    };
  },
  methods: {
    findOrderDetail(id) {
      this.$axios
        .get(`${Api.HTTP.findOrderDetail}?id=${id}`)
        .then(res => {
          console.log(res.data);
          this.info = res.data;
        })
        .catch(function(error) {
          Toast("网络错误");
          console.log(error);
        });
    },
    confirmOrder() {
      let id = this.id;
      this.$axios
        .get(`${Api.HTTP.confirmOrder}?id=${id}`)
        .then(res => {
          console.log(res.data);
          if (res.data.success) {
            Toast("确认成功");
            this.state = 1;
                setTimeout(()=>{
              this.$router.go(-1);
            },1000);
          }
        })
        .catch(function(error) {
          Toast("网络错误");
          console.log(error);
        });
    }
  },
  mounted() {
    this.pubilcM.setTitle("业务详情");
    this.findOrderDetail(this.$route.query.id);
    this.id = this.$route.query.id;
    this.name = this.$route.query.name;
    this.state = this.$route.query.state;

    console.log(this.state);
  }
};
</script>
<style scoped>
.container {
  width: 100%;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  top: 0;
  background: #f6f5f5;
  padding-bottom: 1.2rem;
}
.btn {
  position: fixed;
  left: 0;
  right: 0;
  height: 1.2rem;
  bottom: 0;
  padding: 0.2rem;
  background: #fff;
  box-sizing: border-box;
}
.proName {
  padding: 0.25rem;
}
.proDetail {
  padding: 0.25rem;
  box-sizing: border-box;
  background: #fff;
}
.item {
  padding-bottom: 0.2rem;
  border-bottom: 1px solid #eeeeee;
  margin-bottom: 0.2rem;
}
.item div:nth-child(1) {
  color: #999999;
  margin-bottom: 0.2rem;
}
.item div:nth-child(2) {
}
</style>